package com.stcc.portal.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * 描述:注册Servlet
 * Java Servlet是运行在Web服务器或应用服务器上的程序，作为来自Web浏览器
 * 或其他HTTP客户端的请求和HTTP服务器上的数据库或应用程序之间的中间层
 * 项目名:stcc_gl-parent
 * 包名:com.stcc.portal.config
 * 作者:stcc
 * 创建时间:2021/3/11 10:35
 * 版本:1.0
 */
@Configuration
public class ServletConfig {
    /**
     * 注册PC Servlet
     * @return servletRegistrationBean
     */
    @Bean
    public ServletRegistrationBean PCServlet(DispatcherServlet dispatcherServlet) {

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        dispatcherServlet.setApplicationContext(applicationContext);
        servletRegistrationBean.addUrlMappings("/pc/*");
        servletRegistrationBean.setLoadOnStartup(-1);
        servletRegistrationBean.setName("pc");
        return servletRegistrationBean;

    }
}
